import 'dart:async';

import 'package:flutter/material.dart';
import 'package:my_app/utils/log_util.dart';
import 'package:package_info_plus/package_info_plus.dart';

class ExamplePackageInfoPlusPage extends StatefulWidget {
  const ExamplePackageInfoPlusPage({super.key});

  @override
  State<ExamplePackageInfoPlusPage> createState() => _ExamplePackageInfoPlusPageState();
}

class _ExamplePackageInfoPlusPageState extends State<ExamplePackageInfoPlusPage> {

  PackageInfo _packageInfo = PackageInfo(
    appName: 'Unknown',
    packageName: 'Unknown',
    version: 'Unknown',
    buildNumber: 'Unknown',
    buildSignature: 'Unknown',
    installerStore: 'Unknown',
  );

  Future<void> _initPackageInfo() async {
    final info = await PackageInfo.fromPlatform();
    setState(() {
      _packageInfo = info;
    });
  }

  @override
  void initState() {
    super.initState();
    _initPackageInfo();
  }

  
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text("package-info-plus")),
      body: Center(
        child: ElevatedButton(
          onPressed: () {
            LogUtil.i(_packageInfo);
            LogUtil.i('version: ${_packageInfo.version}');
            LogUtil.i('buildNumber: ${_packageInfo.buildNumber}');
            // LogUtil.v(_deviceData);
          },
          child: const Text("看看包信息数据")
        )
      ),
    );
  }
}